package com.xc.easyExcel;

import com.alibaba.excel.EasyExcel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;

@RestController
@RequestMapping("excelToMysql")
public class ToMysqlFromExcel {
    @Autowired
    private CustomListener listener;

    @GetMapping("/easyExcel")
    public void te(MultipartFile file) {
        InputStream stream;
        try {
            stream = file.getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        EasyExcel.read(stream, listener).sheet(1).headRowNumber(3).doRead();
    }

    public static void main(String[] args) {
        CustomListener listener = new CustomListener();
        File file = new File("D:\\person\\WeChat Files\\wxid_xvjtlx70b8b922\\FileStorage\\File\\2024-04\\绵阳台沃导入表格-new.xlsx");
        FileInputStream stream = null;
        try {
            stream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        EasyExcel.read(stream, listener).sheet(1).headRowNumber(3).doRead();
    }
}
